package com.guide.utils;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;

public class KPBeanUtils {
	static {
		ConvertUtils.register(new DateConverter(null), java.util.Date.class); 
	}
	public static <T> List<T> convertMapList(List<Map> mapList, Class<T> clazz) throws Exception {
		List<T> list = new LinkedList<T>();
		if (mapList == null || mapList.size() == 0) {
			return list;
		}
		for (Map map : mapList) {
			T instance = clazz.newInstance();
			BeanUtils.populate(instance, map);
			list.add(instance);
		} 
		return list;
	}
}
